package qianfan

import (
	"fmt"
	"strconv"

	"gitee.com/bjf-fhe/merge/platform"
)

type QianfanEntry struct {
	Prompt   string `json:"prompt"`
	Response string `json:"response"`
}

func (e *QianfanEntry) SetInstruction(instruction string) {
	e.Prompt = instruction
}

func (e *QianfanEntry) SetInput(input string) {
	e.Prompt += input
}

func (e *QianfanEntry) SetOutput(output string) {
	e.Response = output
}

// MarshalJSON implements the json.Marshaler interface.
func (e *QianfanEntry) MarshalJSON() ([]byte, error) {
	//escape the prompt and response strings
	var escapedPrompt = strconv.Quote(e.Prompt)
	var escapedResponse = strconv.Quote(e.Response)

	fmt.Println("escapedPrompt:", escapedPrompt)
	fmt.Println("escapedResponse:", escapedResponse)

	return []byte(`[{"prompt":` + escapedPrompt + `,"response":[[` + escapedResponse + `]]}]`), nil
}

func init() {
	// Register the LLamaEntry type for use by the qianfan package.
	platform.RegisterEntryType("qianfan", &QianfanEntry{})
}
